package com.mimiwang.chat.controller;

import com.github.pagehelper.PageInfo;
import com.mimiwang.chat.entity.TalkVo;
import com.mimiwang.chat.service.ChatTalkRedisService;
import com.mimiwang.chat.service.ChatTalkService;
import com.mimiwang.common.constant.Constant;
import com.mimiwang.common.utils.ResponseUtil;
import com.mimiwang.common.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/5/13 12:47
 */

@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    ChatTalkService chatTalkService;

    @Autowired
    ChatTalkRedisService redisService;

    @GetMapping("/list/{id}")
    public String getChatHistoryByReceiverId(@PathVariable("id") long receiverId,int pageNum, HttpServletRequest request){
        String header = request.getHeader(Constant.TOKEN_HEADER_NAME);
        String id = TokenUtil.verify(header);

        PageInfo<TalkVo> talkVoPageInfo = chatTalkService.selectAll(Long.parseLong(id), receiverId,pageNum);
        return ResponseUtil.successJSONData(talkVoPageInfo);
    }
}
